<template>
	<div class="layout-pd">

		<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
			<el-table-column prop="hid" label="id" width="300" />
			<el-table-column prop="name" label="作业名称"  width="300"></el-table-column>
			<!-- <el-table-column prop="roleSign" label="角色标识" show-overflow-tooltip></el-table-column>
				<el-table-column prop="sort" label="排序" show-overflow-tooltip></el-table-column> -->

			<!-- <el-table-column prop="describe" label="角色描述" show-overflow-tooltip></el-table-column> -->
			<el-table-column prop="endtime" :formatter="getLocalTime" label="截止时间"  width="400"></el-table-column>
		
			<el-table-column label="操作"  width="300">
				<template #default="scope">
					<el-button size="small" text type="primary" @click="Jump(scope)">查看</el-button>
					<!-- <el-button :disabled="scope.row.roleName === '超级管理员'" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>  -->
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script setup lang="ts" name="funQrcode">
import { storeToRefs } from 'pinia';
import { useUserInfo } from '/@/stores/userInfo';
import { onMounted, reactive, ref } from 'vue';
import { scriptApi } from '/@/api/fun/index';
import router from '/@/router';
import { Session } from '/@/utils/storage';
import { NextLoading } from '/@/utils/loading';



// 定义变量内容
const storesUserInfo = useUserInfo();
const { userInfos } = storeToRefs(storesUserInfo);
const userAuth = ref('');

// 定义变量内容
const state = reactive<SysRoleState>({
	tableData: {
		data: [],
		total: 0,
		loading: false,
		param: {
			hids: [],
			search: '',
			pageNum: 1,
			pageSize: 10,
			states: [],
			getatates:[],
		},
	},
});

// 初始化用户权限
const initUserAuth = () => {
	userAuth.value = userInfos.value.roles[0];
};


// 获取发布的作业
const onRadio = async () => {
	scriptApi().getHomeWork().then(res => {
		state.tableData.data = res.data;
		for (let i = 0; i < state.tableData.data.length; i++) {
			state.tableData.param.states.push(res.data[i].hid)
			Session.set(res.data[i].hid, JSON.stringify(res.data[i].content))
		}
		//获取作业状态
		scriptApi().getState(state.tableData.param.states).then(res => {
			 localStorage.setItem('states', JSON.stringify(res.data))
		})
		state.tableData.param.getatates=JSON.parse(localStorage.getItem("states") || '{}')
	})


};


//格式化后端返回来的时间
function getLocalTime(value: any) {
	let time = value.endtime[0] + '-' + value.endtime[1] + '-' + value.endtime[2] + ' ' + value.endtime[3] + ':' + value.endtime[4] + ':' + value.endtime[5]
	return time
}



//跳转到具体页面
const Jump = (scope: any) => {
	localStorage.setItem('hid', JSON.stringify(scope.row.hid))
	router.push("/fun/tagsView")
}


// 页面加载时
onMounted(() => {
	initUserAuth()
	onRadio()
});


</script>



<!-- <template>
	<div class="qrcode-container layout-pd">
		<el-card shadow="hover" header="qrcodejs2 二维码生成">
			<el-alert
				title="感谢优秀的 `qrcodejs2`，项目地址：https://github.com/davidshimjs/qrcodejs"
				type="success"
				:closable="false"
				class="mb15"
			></el-alert>
			<div class="qrcode-img-warp">
				<div class="mb30 mt30 qrcode-img">
					<div class="qrcode" ref="qrcodeRef"></div>
				</div>
				<el-button type="primary" size="default" @click="onInitQrcode">
					<el-icon>
						<ele-Refresh />
					</el-icon>
					重新生成
				</el-button>
			</div>
		</el-card>
	</div>
</template>

<script setup lang="ts" name="funQrcode">
import { onMounted, ref } from 'vue';
import QRCode from 'qrcodejs2-fixes';

// 定义变量内容
const qrcodeRef = ref();

// 初始化生成二维码
const initQrcode = () => {
	new QRCode(qrcodeRef.value, {
		text: `https://lyt-top.gitee.io/vue-next-admin-preview/#/login?t=${new Date().getTime()}`,
		width: 125,
		height: 125,
		colorDark: '#000000',
		colorLight: '#ffffff',
	});
};
// 重新生成
const onInitQrcode = () => {
	qrcodeRef.value.innerHTML = '';
	initQrcode();
};
// 页面加载时
onMounted(() => {
	initQrcode();
});
</script>

<style scoped lang="scss">
.qrcode-container {
	.qrcode-img-warp {
		text-align: center;
		.qrcode-img {
			display: flex;
			width: 100%;
			height: 125px;
			.qrcode {
				margin: auto;
				width: 125px;
				height: 125px;
			}
		}
	}
}
</style> -->
